﻿using System;
using System.Windows;
using Convertor.Interface;
using Wpf.CommonTools.SystemExtension;
using System.Linq;

namespace Convertor.Plugin.StopCondition
{
    public class Plugin : PluginBase
    {
        #region Static Fun

        static string[] LanguagePaths = new string[] { @"Convertor.Plugin.StopCondition;component\Assets\Lang\StringResource.zh.xaml", @"Convertor.Plugin.StopCondition;component\Assets\Lang\StringResource.en.xaml" };

        static Plugin()
        {
            foreach (string path in LanguagePaths)
            {
                ResourceDictionary resourceDictionary = new ResourceDictionary();
                resourceDictionary.Source = new Uri(path, UriKind.Relative);
                Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
            }
        }

        #endregion

        #region IPluginInfo 成员

        public override string Name
        {
            get { return UILanguage.FindResource("PluginType_System") + " - " + UILanguage.FindResource("Plugin_StopCondition_Name"); }
        }

        public override string Description
        {
            get { return UILanguage.FindResource("Plugin_StopCondition_Desc"); }
        }


        

        

        #endregion

        #region IConvertParamters 成员

        public override IConvertParamters Output(IConvertParamters content)
        {
            if (content == null || content.OutputContent == null)
            {
                if (Log != null) { Log(this, UILanguage.FindResource("Plugin_Common_Input_Output_Null"), LogTypes.Error); }
                return content;
            }

            if (Log != null) { Log(this, config.ToolTip, LogTypes.Normal); }

            switch (config.Condition)
            {
                case ConditionOptions.True:
                    content.StopConvert = content.OutputContent.ToString() == bool.TrueString;
                    break;
                case ConditionOptions.False:
                    content.StopConvert = content.OutputContent.ToString() == bool.FalseString;
                    break;
            }
            if (content.StopConvert)
            {
                if (Log != null) { Log(this, UILanguage.TryFindResource("Plugin_StopCondition_Result_Stop"), LogTypes.Normal | LogTypes.HidePluginName); }
            }
            else
            {
                if (Log != null) { Log(this, UILanguage.TryFindResource("Plugin_StopCondition_Result_Continue"), LogTypes.Normal | LogTypes.HidePluginName); }
            }
            return content;
        }

        #endregion

        #region IPluginConfigForm 成员

        public override PluginConfigForm ConfigForm
        {
            get { return new ConfigForm(); }
        }

        #endregion

        #region IPluginConfig 成员

        private ConfigContent config;
        public override object Config
        {
            get { return config; }
            set { config = (value as ConfigContent) ?? new ConfigContent(); }
        }

        #endregion

    }
}
